import os
from src.base import bera
# 生成 application.yml 文件
def generate_application_yml(templates, output_folder='artifacts/miaoma/springboot/src/main/resources'):
    # 创建 resources 目录
    os.makedirs(output_folder, exist_ok=True)

    # 渲染 application.yml 模板
    yml_code = templates.get_template('springboot/application.yml.j2').render(
        app_version='1.0.1',
        max_file_size=2097152,
        package_timestamp=0,
        git_hash=0,
        upload_directory='/Users/xxxx/test/upload',
        root_url='http://localhost:8080',
        server_port=8080,
        log_file_name='artifacts/logs/myapp.log',
        log_level_root='ERROR',
        log_level_spring='INFO',
        application_name='manager1',
        datasource_url='jdbc:mysql://127.0.0.1:3306/bera?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true',
        datasource_username='root',
        datasource_password='123456',
        static_location1='file:/Users/xxxx/workspace/bera/berapay-tools/assets/beracode/manager/www',
        static_location2='file:/Users/xxxx/test/upload'
    )

    # 写入 application.yml 文件
    yml_file_path = os.path.join(output_folder, 'application.yml')
    with open(yml_file_path, 'w') as f:
        f.write(yml_code)
    bera.logger.info(f"Generated application.yml file at: {yml_file_path}")